//package com.example.demo.bis.elasticsearch.service;
//
//import com.example.demo.demos.pojo.Product;
//import org.elasticsearch.index.query.BoolQueryBuilder;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
//import org.springframework.stereotype.Service;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Service
//public class ProductService {
//
//    @Autowired
//    private ElasticsearchRestTemplate elasticsearchRestTemplate;
//
//    public List<Product> searchProducts(String keyword, Double minPrice, Double maxPrice) {
//        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//
//        if (keyword != null && !keyword.isEmpty()) {
//            boolQuery.must(QueryBuilders.matchQuery("name", keyword));
//        }
//        if (minPrice != null || maxPrice != null) {
//            boolQuery.must(QueryBuilders.rangeQuery("price").gte(minPrice).lte(maxPrice));
//        }
//
//        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
//                .withQuery(boolQuery)
//                .build();
//
//        return elasticsearchRestTemplate.search(searchQuery, Product.class)
//                .getSearchHits()
//                .stream()
//                .map(hit -> hit.getContent())
//                .collect(Collectors.toList());
//    }
//}